package io.commchina.smart.parking.provider.modules.controller.strategy;

import io.commchina.platform.framework.sip.utils.PageUtils;
import io.commchina.platform.framework.tools.Result;
import io.commchina.smart.parking.biz.modules.strategy.CarParkingStrategyService;
import io.commchina.smart.parking.dao.modules.strategy.entity.CarParkingStrategyEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 代码千万行，注释第一行
 * 注释不规范，同事泪两行
 * <p>
 *
 * @author ChenMiLi
 * @version 1.0
 * @date 2021/9/28 14:29
 */

/**
 * 车位策略
 */
@RestController
@Api(tags = "车位策略的控制器")
public class CarParkingStrategyController {

    @Autowired
    private CarParkingStrategyService carParkingStrategyService;

    /**
     * 查询车位策略列表
     *
     * @param params
     * @return
     */
    @GetMapping("/api/v1/carParkingStrategy/list")
    @ApiOperation(value = "查询车位策略列表")
    public Result list(@RequestParam Map<String, Object> params) {
        PageUtils page = carParkingStrategyService.queryPage(params);
        return Result.ok().put("data", page);
    }

    /**
     * 查询指定车位策略
     *
     * @param strategyId
     * @return
     */
    @GetMapping("/api/v1/carParkingStrategy/getByTypeId/{typeId}")
    @ApiOperation(value = "查询指定车位策略")
    @ApiImplicitParam(value = "strategyId", name = "车位策略编号")
    public Result getByTypeId(@PathVariable Integer strategyId) {
        CarParkingStrategyEntity carParkingStrategy = carParkingStrategyService.getByTypeId(strategyId);
        return Result.ok().put("data", carParkingStrategy);
    }

    /**
     * 新增车位策略
     *
     * @param carParkingStrategyEntity
     * @return
     */
    @PostMapping("/api/v1/carParkingStrategy/addStrategy")
    @ApiOperation(value = "新增车位策略")
    public Result addStrategy(@RequestBody CarParkingStrategyEntity carParkingStrategyEntity) {
        carParkingStrategyService.addStrategy(carParkingStrategyEntity);
        return Result.ok();
    }

    /**
     * 删除指定车位策略
     *
     * @param strategyId
     * @return
     */
    @DeleteMapping("/api/v1/carParkingStrategy/deleteStrategy/{strategyId}")
    @ApiOperation(value = "删除指定车位策略")
    @ApiImplicitParam(value = "strategyId", name = "车位策略编号")
    public Result deleteStrategy(@PathVariable Integer strategyId) {
        carParkingStrategyService.deleteStrategy(strategyId);
        return Result.ok();
    }

    /**
     * 更新车位策略
     * @param carParkingStrategyEntity
     * @return
     */
    @PutMapping("/api/v1/carParkingStrategy/updateStrategy")
    @ApiOperation(value = "更新车位策略",notes = "根据车型编号更新车位策略")
    public Result updateStrategy(@RequestBody CarParkingStrategyEntity carParkingStrategyEntity) {
        carParkingStrategyService.updateStrategy(carParkingStrategyEntity);
        return Result.ok();
    }
}
